﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KenLib.BusinessManager;

public partial class APP_frmA_CompHistoryInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((APP_MasterPage_appCom)this.Master).changeTitle("組合員企業履歴情報");
        ((APP_MasterPage_appCom)this.Master).HideLiArea("frmA_CompHistoryInfo");
        
            if (Session["役"] == null || Session["役"] == "" || Session["役"] == "1")
            {
                Response.Redirect("~/frmD_Login.aspx");
            }
            else
            {
            
                if (Request.QueryString["Year"] == null)
                {
                    Response.Redirect("frmA_CompBasicInfo.aspx");
                }
                else
                {
                    string Str = Request.QueryString["Year"].ToString();
                    int Num;
                    bool isNum = int.TryParse(Str, out Num);
                    if (!isNum)
                    {
                        Response.Redirect("frmA_CompBasicInfo.aspx");
                    }
                    else if (Str.Length > 4)
                    {
                        Response.Redirect("frmA_CompBasicInfo.aspx");
                    }
                    else
                    {
                        this.checkCompHistoryInfo();
                        this.Showlabel();// hien thi nam cho lbl_年度.
                        this.ShowCompHistoryInfo();// hien thi chi tiet cac thong tin ve lich su cua cong ty tiep nhan theo tung nam.
                    }
                }
            }

        
        
    }
    protected void lbtn_修正_Click(object sender, EventArgs e)
    {

    }
    public void Showlabel()// hien thi nam cho lbl_年度.
    {
        string year = Request.QueryString["Year"];
        year = year.Substring(0, 4) + "年度";
        
        lbl_年度.Text = year;
    }
    public string ConvertDate(string str)// ham convert ngay thang nam.
    {
        if (str == "")
        {
            return str = "";
        }
        else
        {
            string date = str;
            DateTime d1 = DateTime.Parse(date);
            d1.Year.ToString();
            return date = d1.ToString("yyyy年MM月dd日");
        }
    }

    public void checkCompHistoryInfo()
    {
        int 企業ID = Int32.Parse(Session["企業コード_2"].ToString()); // Lay ID cua cong ty khi dang nhap
        int year = Int32.Parse(Request.QueryString["Year"].Substring(0, 4));

        本社情報Manager frm = new 本社情報Manager();
        DataTable dt = new DataTable();
        dt = frm.Select_frmA_CompHistoryInfo(企業ID, year);
        if (dt.Rows.Count == 0)
        {
            lbtn_修正.Enabled = false;
        }
    }
    public void ShowCompHistoryInfo() // hien thi chi tiet cac thong tin ve lich su cua cong ty tiep nhan theo tung nam.
    {
        try
        {
            int 企業ID = Int32.Parse(Session["企業コード_2"].ToString()); // Lay ID cua cong ty khi dang nhap
            int year = Int32.Parse(Request.QueryString["Year"].Substring(0,4));
            
            本社情報Manager frm = new 本社情報Manager();
            DataTable dt = new DataTable();
            dt = frm.Select_frmA_CompHistoryInfo(企業ID, year);
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    lbl_組合員企業名.Text = row["企業名"].ToString();
                    lbl_設立年月日.Text = ConvertDate(row["設立年月日"].ToString());
                    lbl_英語.Text = row["企業名英語"].ToString();

                    if (row["資本金"].ToString() == "")
                    {
                        lbl_資本金.Text = row["資本金"].ToString();
                    }
                    else
                    {
                        if (Convert.ToDecimal(row["資本金"]) == 0)
                        {
                            lbl_資本金.Text = "0";
                            lbl_資本金_円.Visible = true;
                        }
                        else
                        {
                            lbl_資本金.Text = Convert.ToDecimal(row["資本金"]).ToString("###,###");
                            lbl_資本金_円.Visible = true;
                        }
                    }

                    lbl_フリガナ.Text = row["企業名フリガナ"].ToString();
                    lbl_業種分類.Text = row["業種分類"].ToString();
                    lbl_郵便番号.Text = row["郵便番号"].ToString();
                    lbl_事業内容.Text = row["事業内容"].ToString();
                    lbl_事業内容その他.Text = row["事業内容その他"].ToString();
                    lbl_住所.Text = row["住所"].ToString();
                    lbl_主要製品.Text = row["主要製品"].ToString();
                    lbl_電話番号.Text = row["ＴＥＬ"].ToString();
                    lbl_FAX番号.Text = row["FAX"].ToString();

                    if (row["売上"].ToString() == "")
                    {
                        lbl_売上.Text = row["売上"].ToString();
                    }
                    else
                    {
                        if (Convert.ToDecimal(row["売上"]) == 0)
                        {
                            lbl_売上.Text = "0";
                            donvi1.Visible = true;
                        }
                        else
                        {
                            lbl_売上.Text = Convert.ToDecimal(row["売上"]).ToString("###,###");
                            donvi1.Visible = true;
                        }
                    }

                    if (row["大卒初任給"].ToString() == "")
                    {
                        lbl_大卒初任給.Text = row["大卒初任給"].ToString();
                        trong1.Visible = true;
                    }
                    else
                    {
                        lbl_大卒初任給.Text = Convert.ToDecimal(row["大卒初任給"]).ToString("###,###");
                        donvi5.Visible = true;
                    }

                    if (row["営業損益"].ToString() == "")
                    {
                        lbl_営業損益.Text = row["営業損益"].ToString();

                    }
                    else
                    {
                        lbl_営業損益.Text = Convert.ToDecimal(row["営業損益"]).ToString("###,###");
                        donvi2.Visible = true;
                    }


                    if (row["高卒初任給"].ToString() == "")
                    {
                        lbl_高卒初任給.Text = row["高卒初任給"].ToString();
                        trong2.Visible = true;
                    }
                    else
                    {
                        lbl_高卒初任給.Text = Convert.ToDecimal(row["高卒初任給"]).ToString("###,###");
                        donvi6.Visible = true;
                    }


                    if (row["経営損益"].ToString() == "")
                    {
                        lbl_経常損益.Text = row["経営損益"].ToString();
                    }
                    else
                    {
                        lbl_経常損益.Text = Convert.ToDecimal(row["経営損益"]).ToString("###,###");
                        donvi3.Visible = true;
                    }


                    if (row["中卒初任給"].ToString() == "")
                    {
                        lbl_中卒初任給.Text = row["中卒初任給"].ToString();
                        trong3.Visible = true;
                    }
                    else
                    {
                        lbl_中卒初任給.Text = Convert.ToDecimal(row["中卒初任給"]).ToString("###,###");
                        donvi7.Visible = true;
                    }

                    if (row["当期損益"].ToString() == "")
                    {
                        lbl_当期純損益.Text = row["当期損益"].ToString();
                    }
                    else
                    {
                        lbl_当期純損益.Text = Convert.ToDecimal(row["当期損益"]).ToString("###,###");
                        donvi4.Visible = true;
                    }

                    if (row["年間労働日数"].ToString() == "")
                    {
                        lbl_年間労働日数.Text = row["年間労働日数"].ToString();
                    }
                    else
                    {
                        lbl_年間労働日数.Text = row["年間労働日数"].ToString();
                        donvi8.Visible = true;
                    }

                    if (row["勤務開始時間"].ToString() == "")
                    {
                        lbl_勤務開始時間.Text = row["勤務開始時間"].ToString();
                    }
                    else
                    {
                        lbl_勤務開始時間.Text = row["勤務開始時間"].ToString();
                        donvi9.Visible = true;

                    }

                    if (row["昼休み開始時間"].ToString() == "")
                    {
                        lbl_昼休み開始時間.Text = row["昼休み開始時間"].ToString();
                        trong4.Visible = true;
                    }
                    else
                    {
                        lbl_昼休み開始時間.Text = row["昼休み開始時間"].ToString();
                        donvi10.Visible = true;
                    }
                    lbl_常勤事務職_男性.Text = row["常勤事務男"].ToString();
                    lbl_常勤事務職_女性.Text = row["常勤事務女"].ToString();

                    if (row["昼休み終了時間"].ToString() == "")
                    {
                        lbl_昼休み終了時間.Text = row["昼休み終了時間"].ToString();
                        trong5.Visible = true;
                    }
                    else
                    {
                        lbl_昼休み終了時間.Text = row["昼休み終了時間"].ToString();
                        donvi11.Visible = true;
                    }


                    lbl_常勤現場職_男性.Text = row["常勤現場男"].ToString();
                    lbl_常勤現場職_女性.Text = row["常勤現場女"].ToString();

                    if (row["勤務終了時間"].ToString() == "")
                    {
                        lbl_勤務終了時間.Text = row["勤務終了時間"].ToString();
                    }
                    else
                    {
                        lbl_勤務終了時間.Text = row["勤務終了時間"].ToString();
                        donvi12.Visible = true;
                    }


                    if (row["非常勤事務男"].ToString() == "")
                    {
                        lbl_非常勤事務職_男性.Text = row["非常勤事務男"].ToString();
                        trong9.Visible = true;
                    }
                    else
                    {
                        lbl_非常勤事務職_男性.Text = row["非常勤事務男"].ToString();
                    }

                    if (row["非常勤現場女"].ToString() == "")
                    {
                        lbl_非常勤事務職_女性.Text = row["非常勤現場女"].ToString();
                        trong10.Visible = true;
                    }
                    else
                    {
                        lbl_非常勤事務職_女性.Text = row["非常勤現場女"].ToString();
                    }

                    if (row["休憩時間"].ToString() == "")
                    {
                        lbl_休憩合計時間.Text = row["休憩時間"].ToString();
                        trong6.Visible = true;
                    }
                    else
                    {
                        lbl_休憩合計時間.Text = row["休憩時間"].ToString();
                        donvi13.Visible = true;
                    }



                    if (row["非常勤事務男"].ToString() == "")
                    {
                        lbl_合計_男性.Text = Convert.ToString(Int32.Parse(row["常勤事務男"].ToString()) + Int32.Parse(row["常勤現場男"].ToString()) + 0);
                    }
                    else
                    {
                        lbl_合計_男性.Text = Convert.ToString(Int32.Parse(row["常勤事務男"].ToString()) + Int32.Parse(row["常勤現場男"].ToString()) + Int32.Parse(row["非常勤事務男"].ToString()));
                    }


                    if (row["非常勤現場女"].ToString() == "")
                    {
                        lbl_合計_女性.Text = Convert.ToString(Int32.Parse(row["常勤事務女"].ToString()) + Int32.Parse(row["常勤現場女"].ToString()) + 0);
                    }
                    else
                    {

                        lbl_合計_女性.Text = Convert.ToString(Int32.Parse(row["常勤事務女"].ToString()) + Int32.Parse(row["常勤現場女"].ToString()) + Int32.Parse(row["非常勤現場女"].ToString()));
                    }

                    if (row["所定労働時間"].ToString() == "")
                    {
                        lbl_所定労働時間.Text = row["所定労働時間"].ToString();
                        trong7.Visible = true;
                    }
                    else
                    {
                        if (Int32.Parse(row["所定労働時間"].ToString()) < 10)
                        {
                            lbl_所定労働時間.Text = "0" + row["所定労働時間"].ToString();
                            donvi14.Visible = true;
                        }
                        else
                        {
                            lbl_所定労働時間.Text = row["所定労働時間"].ToString();
                            donvi14.Visible = true;
                        }
                    }

                    if (Int32.Parse(row["所定労働時間_分"].ToString()) < 10)
                    {
                        lbl_所定労働時間_分.Text = "0" + row["所定労働時間_分"].ToString() + "分";
                    }
                    else
                    {
                        lbl_所定労働時間_分.Text = row["所定労働時間_分"].ToString() + "分";
                    }




                    if (row["平均週間労働日数"].ToString() == "")
                    {
                        lbl_週平均労働日数.Text = row["平均週間労働日数"].ToString();
                        trong8.Visible = true;
                    }
                    else
                    {
                        lbl_週平均労働日数.Text = row["平均週間労働日数"].ToString();
                        donvi15.Visible = true;

                    }

                }
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "myScripts", "<script language='javascript'>alert('この年度の情報がまだ入力していません。');</script>", false);
                lbl_組合員企業名.Text = "-";
                lbl_設立年月日.Text = "-";
                lbl_英語.Text = "-";
                lbl_資本金.Text = "-";
                lbl_フリガナ.Text = "-";
                lbl_業種分類.Text = "-";
                lbl_郵便番号.Text = "-";
                lbl_事業内容.Text = "-";
                lbl_住所.Text = "-";
                lbl_主要製品.Text = "-";
                lbl_電話番号.Text = "-";
                lbl_FAX番号.Text = "-";
                lbl_売上.Text = "-";
                lbl_大卒初任給.Text = "-";
                lbl_営業損益.Text = "-";
                lbl_高卒初任給.Text = "-";
                lbl_経常損益.Text = "-";
                lbl_中卒初任給.Text = "-";
                lbl_当期純損益.Text = "-";
                lbl_年間労働日数.Text = "-";
                lbl_勤務開始時間.Text = "-";
                lbl_昼休み開始時間.Text = "-";
                lbl_常勤事務職_男性.Text = "-";
                lbl_常勤事務職_女性.Text = "-";
                lbl_昼休み終了時間.Text = "-";
                lbl_常勤現場職_男性.Text = "-";
                lbl_常勤現場職_女性.Text = "-";
                lbl_勤務終了時間.Text = "-";
                lbl_非常勤事務職_男性.Text = "-";
                lbl_非常勤事務職_女性.Text = "-";
                lbl_休憩合計時間.Text = "-";
                lbl_合計_男性.Text = "-";
                lbl_合計_女性.Text = "-";
                lbl_所定労働時間.Text = "-";
                lbl_週平均労働日数.Text = "-";

            }
                           
        }
        catch { }

    }

    protected void lbtn_修正_Click1(object sender, EventArgs e)
    {
        Session["Update_frmA_History_Fom_HistoryInfo"] = "Update";
        string year = Request.QueryString["Year"].Substring(0, 4);
        Session["GetYar_Fom_HistoryInfo"] = year;
        Response.Redirect("frmA_CompHistoryInput.aspx");
    }
}
